package com.incar.chuxing.baiduMap;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.baidu.mapapi.bikenavi.BikeNavigateHelper;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.walknavi.WalkNavigateHelper;
import com.baidu.mapapi.walknavi.adapter.IWEngineInitListener;
import com.baidu.mapapi.walknavi.adapter.IWRoutePlanListener;
import com.baidu.mapapi.walknavi.model.WalkRoutePlanError;
import com.baidu.mapapi.walknavi.params.WalkNaviLaunchParam;
import com.incar.chuxing.activity.WalkNaviActivity;

/**
 * Created by Michael on 11/6.
 */

public class WalkNavi {
    private Activity activity;
    private WalkNavigateHelper mWNaviHelper;
    private BikeNavigateHelper mNaviHelper;

    public WalkNavi(Activity activity) {
        this.activity = activity;
    }

    public void startWalkNavi(LatLng startPt, LatLng endPt) {

        //BikeNaviLaunchParam  param = new BikeNaviLaunchParam().stPt(startPt).endPt(endPt);
        final WalkNaviLaunchParam walkParam = new WalkNaviLaunchParam().stPt(startPt).endPt(endPt);
        try {
            //mNaviHelper = BikeNavigateHelper.getInstance();
            mWNaviHelper = WalkNavigateHelper.getInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.d("View", "startBikeNavi");
        try {
            mWNaviHelper.initNaviEngine(activity, new IWEngineInitListener() {
                @Override
                public void engineInitSuccess() {
                    Log.d("View", "engineInitSuccess");
                    routePlanWithWalkParam(walkParam);
                }

                @Override
                public void engineInitFail() {
                    Log.d("View", "engineInitFail");
                }
            });
        } catch (Exception e) {
            Log.d("Exception", "startBikeNavi");
            e.printStackTrace();
        }
    }

    private void routePlanWithWalkParam(WalkNaviLaunchParam walkParam) {
        mWNaviHelper.routePlanWithParams(walkParam, new IWRoutePlanListener() {
            @Override
            public void onRoutePlanStart() {
                Log.d("View", "onRoutePlanStart");
            }

            @Override
            public void onRoutePlanSuccess() {
                Log.d("View", "onRoutePlanSuccess");
                Intent intent = new Intent();
                intent.setClass(activity, WalkNaviActivity.class);
                activity.startActivity(intent);
            }

            @Override
            public void onRoutePlanFail(WalkRoutePlanError error) {
                Log.d("View", "onRoutePlanFail");
            }

        });
    }
}
